package com.ruitu.health.support.push.hw_push;

import android.text.TextUtils;

import com.huawei.hms.push.HmsMessageService;
import com.huawei.hms.push.RemoteMessage;
import com.ruitu.router_module.Logg;

/**
 * 华为推送消息接收服务
 * onMessageReceived()方法会在推送透传消息的时候回调,通知栏消息不回调
 * 华为推送的透传消息在应用杀死后无效,通知栏消息可以在应用杀死后接收到消息
 */
public class MyHmsMessageService extends HmsMessageService {

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        Logg.i("收到华为推送消息(注意:通知栏消息不会回调该方法!)...");

        // TODO(developer): Handle HCM messages here.
        Logg.i("From: " + remoteMessage.getFrom());

        // Check if message contains a data payload.
        if (remoteMessage.getData().length() > 0) {
            Logg.i("Message data payload: " + remoteMessage.getData());
            if (/* Check if data needs to be processed by long running job */ true) {
                // For long-running tasks (10 seconds or more) use job.
//                scheduleJob();
            } else {
                // Handle message within 10 seconds
//                handleNow();
            }
        }

        // Check if message contains a notification payload.
        if (remoteMessage.getNotification() != null) {
            Logg.i("Message Notification Body: " + remoteMessage.getNotification().getBody());
        }
    }

    @Override
    public void onDeletedMessages() {
        super.onDeletedMessages();
    }

    @Override
    public void onMessageSent(String s) {
        super.onMessageSent(s);
    }

    @Override
    public void onSendError(String s, Exception e) {
        super.onSendError(s, e);
    }

    @Override
    public void onNewToken(String newToken) {
        if (!TextUtils.isEmpty(newToken)) {
            Logg.i("华为推送newToken = " + newToken);
        } else {
            Logg.i("华为推送newToken = " + newToken);
        }
    }
}
